//
//  AccountSecurityVC.m
//  Recycling
//
//  Created by jzd on 2018/5/17.
//  Copyright © 2018年 宋佳. All rights reserved.
//

#import "AccountSecurityVC.h"
#import "LoginViewController.h"
#import "ReplacePwdVC.h"

@interface AccountSecurityVC ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topCons;
@property (weak, nonatomic) IBOutlet UIImageView *topImage;
@property (weak, nonatomic) IBOutlet UILabel *userName;

@end

@implementation AccountSecurityVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = BGCOLOR;
    self.navigationItem.title = @"账户安全";
    self.topCons.constant = statsBarHeight+NavgationBarH;
    [self refreshUI];
}
-(void)refreshUI{
    NSString *imageUrl = [UserInfoTool shareUserInfoTool].Info.HeadImg;
    [self.topImage sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
    self.userName.text = [UserInfoTool shareUserInfoTool].Info.UserName;
}
- (IBAction)replacePwdOnClick:(UIButton *)sender {
    ReplacePwdVC *vc = [[ReplacePwdVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)logOutOnClick:(UIButton *)sender {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"退出登录" message:@"您确认要退出当前登录的账号吗?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        LoginViewController *vc = [[LoginViewController alloc]init];
        [UIApplication sharedApplication].keyWindow.rootViewController = vc;
        
        //移除别名
        if ([[NSUserDefaults standardUserDefaults]objectForKey:DeviceToken]) {
            if ([[UserInfoTool shareUserInfoTool].Info.Role  isEqualToString:@"030003002"]) {
                //移除别名
                NSString *alias = [NSString stringWithFormat:@"%d",[UserInfoTool shareUserInfoTool].Info.ID];
                [UMessage removeAlias:alias type:@"WORKER_TYPE" response:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
                }];
            }
        }
        
        
    }];
    alert.view.tintColor = TITLECOLOR;
    [alert addAction:cancel];
    [alert addAction:sure];
    [self presentViewController:alert animated:YES completion:nil];
}


@end
